|
1
|
|
|
/*! |
|
2
|
|
|
* @name ElkArte Forum |
|
3
|
|
|
* @copyright ElkArte Forum contributors |
|
4
|
|
|
* @license BSD http://opensource.org/licenses/BSD-3-Clause |
|
5
|
|
|
* |
|
6
|
|
|
* This file contains code covered by: |
|
7
|
|
|
* copyright: 2011 Simple Machines (http://www.simplemachines.org) |
|
8
|
|
|
* license: BSD, See included LICENSE.TXT for terms and conditions. |
|
9
|
|
|
* |
|
10
|
|
|
* @version 1.1.1 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* This file contains javascript associated with the topic viewing including |
|
15
|
|
|
* Quick Modify, Quick Reply, In Topic Moderation, thumbnail expansion etc |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* *** QuickModifyTopic object. |
|
20
|
|
|
* Used to quick edit a topic subject by double clicking next to the subject name |
|
21
|
|
|
* in a topic listing |
|
22
|
|
|
* |
|
23
|
|
|
* @param {object} oOptions |
|
24
|
|
|
*/ |
|
25
|
|
|
function QuickModifyTopic(oOptions) |
|
26
|
|
|
{ |
|
27
|
|
|
this.opt = oOptions; |
|
28
|
|
|
this.aHidePrefixes = this.opt.aHidePrefixes; |
|
29
|
|
|
this.iCurTopicId = 0; |
|
30
|
|
|
this.sCurMessageId = ''; |
|
31
|
|
|
this.sBuffSubject = ''; |
|
32
|
|
|
this.oSavetipElem = false; |
|
33
|
|
|
this.oCurSubjectDiv = null; |
|
34
|
|
|
this.oTopicModHandle = document; |
|
35
|
|
|
this.bInEditMode = false; |
|
36
|
|
|
this.bMouseOnDiv = false; |
|
37
|
|
|
this.init(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
// Used to initialise the object event handlers |
|
41
|
|
|
QuickModifyTopic.prototype.init = function () |
|
42
|
|
|
{ |
|
43
|
|
|
// Detect and act on keypress |
|
44
|
|
|
this.oTopicModHandle.onkeydown = this.modify_topic_keypress.bind(this); |
|
45
|
|
|
|
|
46
|
|
|
// Used to detect when we've stopped editing. |
|
47
|
|
|
this.oTopicModHandle.onclick = this.modify_topic_click.bind(this); |
|
48
|
|
|
}; |
|
49
|
|
|
|
|
50
|
|
|
// called from the double click in the div |
|
51
|
|
|
QuickModifyTopic.prototype.modify_topic = function (topic_id, first_msg_id) |
|
52
|
|
|
{ |
|
53
|
|
|
// already editing |
|
54
|
|
|
if (this.bInEditMode) |
|
55
|
|
|
{ |
|
56
|
|
|
// Same message then just return, otherwise drop out of this edit. |
|
57
|
|
|
if (this.iCurTopicId === topic_id) |
|
58
|
|
|
return; |
|
59
|
|
|
else |
|
60
|
|
|
this.modify_topic_cancel(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
this.bInEditMode = true; |
|
64
|
|
|
this.bMouseOnDiv = true; |
|
65
|
|
|
this.iCurTopicId = topic_id; |
|
66
|
|
|
|
|
67
|
|
|
// Get the topics current subject |
|
68
|
|
|
ajax_indicator(true); |
|
69
|
|
|
sendXMLDocument.call(this, elk_prepareScriptUrl(elk_scripturl) + "action=quotefast;quote=" + first_msg_id + ";modify;xml", '', this.onDocReceived_modify_topic); |
|
70
|
|
|
}; |
|
71
|
|
|
|
|
72
|
|
|
// Callback function from the modify_topic ajax call |
|
73
|
|
|
QuickModifyTopic.prototype.onDocReceived_modify_topic = function (XMLDoc) |
|
74
|
|
|
{ |
|
75
|
|
|
// If it is not valid then clean up |
|
76
|
|
|
if (!XMLDoc || !XMLDoc.getElementsByTagName('message')) |
|
77
|
|
|
{ |
|
78
|
|
|
this.modify_topic_cancel(); |
|
79
|
|
|
return true; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
this.sCurMessageId = XMLDoc.getElementsByTagName("message")[0].getAttribute("id"); |
|
83
|
|
|
this.oCurSubjectDiv = document.getElementById('msg_' + this.sCurMessageId.substr(4)); |
|
84
|
|
|
this.sBuffSubject = this.oCurSubjectDiv.innerHTML; |
|
85
|
|
|
|
|
86
|
|
|
// Hide the tooltip text, don't want them for this element during the edit |
|
87
|
|
|
if ($.isFunction($.fn.SiteTooltip)) |
|
88
|
|
|
{ |
|
89
|
|
|
this.oSavetipElem = this.oCurSubjectDiv.nextSibling; |
|
90
|
|
|
this.sSavetip = this.oSavetipElem.innerHTML; |
|
91
|
|
|
this.oSavetipElem.innerHTML = ''; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
// Here we hide any other things they want hidden on edit. |
|
95
|
|
|
this.set_hidden_topic_areas('none'); |
|
96
|
|
|
|
|
97
|
|
|
// Show we are in edit mode and allow the edit |
|
98
|
|
|
ajax_indicator(false); |
|
99
|
|
|
this.modify_topic_show_edit(XMLDoc.getElementsByTagName("subject")[0].childNodes[0].nodeValue); |
|
100
|
|
|
}; |
|
101
|
|
|
|
|
102
|
|
|
// Cancel out of an edit and return things to back to what they were |
|
103
|
|
|
QuickModifyTopic.prototype.modify_topic_cancel = function () |
|
104
|
|
|
{ |
|
105
|
|
|
this.oCurSubjectDiv.innerHTML = this.sBuffSubject; |
|
106
|
|
|
this.set_hidden_topic_areas(''); |
|
107
|
|
|
this.bInEditMode = false; |
|
108
|
|
|
|
|
109
|
|
|
// Put back the hover text |
|
110
|
|
|
if (this.oSavetipElem !== false) |
|
111
|
|
|
this.oSavetipElem.innerHTML = this.sSavetip; |
|
112
|
|
|
|
|
113
|
|
|
return false; |
|
114
|
|
|
}; |
|
115
|
|
|
|
|
116
|
|
|
// Simply restore/show any hidden bits during topic editing. |
|
117
|
|
|
QuickModifyTopic.prototype.set_hidden_topic_areas = function (set_style) |
|
118
|
|
|
{ |
|
119
|
|
|
for (var i = 0; i < this.aHidePrefixes.length; i++) |
|
120
|
|
|
{ |
|
121
|
|
|
if (document.getElementById(this.aHidePrefixes[i] + this.sCurMessageId.substr(4)) !== null) |
|
122
|
|
|
document.getElementById(this.aHidePrefixes[i] + this.sCurMessageId.substr(4)).style.display = set_style; |
|
123
|
|
|
} |
|
124
|
|
|
}; |
|
125
|
|
|
|
|
126
|
|
|
// For templating, shown that an inline edit is being made. |
|
127
|
|
|
QuickModifyTopic.prototype.modify_topic_show_edit = function (subject) |
|
128
|
|
|
{ |
|
129
|
|
|
// Just template the subject. |
|
130
|
|
|
this.oCurSubjectDiv.innerHTML = '<input type="text" name="subject" value="' + subject + '" size="60" style="width: 95%;" maxlength="80" class="input_text" autocomplete="off" /><input type="hidden" name="topic" value="' + this.iCurTopicId + '" /><input type="hidden" name="msg" value="' + this.sCurMessageId.substr(4) + '" />'; |
|
131
|
|
|
|
|
132
|
|
|
// Attach mouse over and out events to this new div |
|
133
|
|
|
this.oCurSubjectDiv.onmouseout = this.modify_topic_mouseout.bind(this); |
|
134
|
|
|
this.oCurSubjectDiv.onmouseover = this.modify_topic_mouseover.bind(this); |
|
135
|
|
|
}; |
|
136
|
|
|
|
|
137
|
|
|
// Yup that's right, save it |
|
138
|
|
|
QuickModifyTopic.prototype.modify_topic_save = function (cur_session_id, cur_session_var) |
|
139
|
|
|
{ |
|
140
|
|
|
if (!this.bInEditMode) |
|
141
|
|
|
return true; |
|
142
|
|
|
|
|
143
|
|
|
var x = []; |
|
144
|
|
|
|
|
145
|
|
|
x[x.length] = 'subject=' + document.forms.quickModForm.subject.value.replace(/&#/g, "&#").php_urlencode(); |
|
146
|
|
|
x[x.length] = 'topic=' + parseInt(document.forms.quickModForm.elements.topic.value); |
|
147
|
|
|
x[x.length] = 'msg=' + parseInt(document.forms.quickModForm.elements.msg.value); |
|
148
|
|
|
|
|
149
|
|
|
// Send in the call to save the updated topic subject |
|
150
|
|
|
ajax_indicator(true); |
|
151
|
|
|
sendXMLDocument.call(this, elk_prepareScriptUrl(elk_scripturl) + "action=jsmodify;topic=" + parseInt(document.forms.quickModForm.elements.topic.value) + ";" + cur_session_var + "=" + cur_session_id + ";xml", x.join("&"), this.modify_topic_done); |
|
152
|
|
|
|
|
153
|
|
|
return false; |
|
154
|
|
|
}; |
|
155
|
|
|
|
|
156
|
|
|
// Done with the edit, if all went well show the new topic title |
|
157
|
|
|
QuickModifyTopic.prototype.modify_topic_done = function (XMLDoc) |
|
158
|
|
|
{ |
|
159
|
|
|
ajax_indicator(false); |
|
160
|
|
|
|
|
161
|
|
|
// If it is not valid then clean up |
|
162
|
|
|
if (!XMLDoc || !XMLDoc.getElementsByTagName('subject')) |
|
163
|
|
|
{ |
|
164
|
|
|
this.modify_topic_cancel(); |
|
165
|
|
|
return true; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
var message = XMLDoc.getElementsByTagName("elk")[0].getElementsByTagName("message")[0], |
|
169
|
|
|
subject = message.getElementsByTagName("subject")[0], |
|
170
|
|
|
error = message.getElementsByTagName("error")[0]; |
|
171
|
|
|
|
|
172
|
|
|
// No subject or other error? |
|
173
|
|
|
if (!subject || error) |
|
174
|
|
|
return false; |
|
175
|
|
|
|
|
176
|
|
|
this.modify_topic_hide_edit(subject.childNodes[0].nodeValue); |
|
177
|
|
|
this.set_hidden_topic_areas(''); |
|
178
|
|
|
this.bInEditMode = false; |
|
179
|
|
|
|
|
180
|
|
|
// Redo tooltips if they are on since we just pulled the rug out on this one |
|
181
|
|
|
if ($.isFunction($.fn.SiteTooltip)) |
|
182
|
|
|
{ |
|
183
|
|
|
this.oSavetipElem.innerHTML = this.sSavetip; |
|
184
|
|
|
$('.preview').SiteTooltip(); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
return false; |
|
188
|
|
|
}; |
|
189
|
|
|
|
|
190
|
|
|
// Done with the edit, put in new subject and link. |
|
191
|
|
|
QuickModifyTopic.prototype.modify_topic_hide_edit = function (subject) |
|
192
|
|
|
{ |
|
193
|
|
|
// Re-template the subject! |
|
194
|
|
|
this.oCurSubjectDiv.innerHTML = '<a href="' + elk_scripturl + '?topic=' + this.iCurTopicId + '.0">' + subject + '<' +'/a>'; |
|
195
|
|
|
}; |
|
196
|
|
|
|
|
197
|
|
|
// keypress event ... like enter or escape |
|
198
|
|
|
QuickModifyTopic.prototype.modify_topic_keypress = function (oEvent) |
|
199
|
|
|
{ |
|
200
|
|
|
if (typeof(oEvent.keyCode) !== "undefined" && this.bInEditMode) |
|
201
|
|
|
{ |
|
202
|
|
|
if (oEvent.keyCode === 27) |
|
203
|
|
|
{ |
|
204
|
|
|
this.modify_topic_cancel(); |
|
205
|
|
|
if (typeof(oEvent.preventDefault) === "undefined") |
|
206
|
|
|
oEvent.returnValue = false; |
|
207
|
|
|
else |
|
208
|
|
|
oEvent.preventDefault(); |
|
209
|
|
|
} |
|
210
|
|
|
else if (oEvent.keyCode === 13) |
|
211
|
|
|
{ |
|
212
|
|
|
this.modify_topic_save(elk_session_id, elk_session_var); |
|
213
|
|
|
if (typeof(oEvent.preventDefault) === "undefined") |
|
214
|
|
|
oEvent.returnValue = false; |
|
215
|
|
|
else |
|
216
|
|
|
oEvent.preventDefault(); |
|
217
|
|
|
} |
|
218
|
|
|
} |
|
219
|
|
|
}; |
|
220
|
|
|
|
|
221
|
|
|
// A click event to signal the finish of the edit |
|
222
|
|
|
QuickModifyTopic.prototype.modify_topic_click = function (oEvent) |
|
223
|
|
|
{ |
|
224
|
|
|
if (this.bInEditMode && !this.bMouseOnDiv) |
|
225
|
|
|
this.modify_topic_save(elk_session_id, elk_session_var); |
|
226
|
|
|
}; |
|
227
|
|
|
|
|
228
|
|
|
// Moved out of the editing div |
|
229
|
|
|
QuickModifyTopic.prototype.modify_topic_mouseout = function (oEvent) |
|
230
|
|
|
{ |
|
231
|
|
|
this.bMouseOnDiv = false; |
|
232
|
|
|
}; |
|
233
|
|
|
|
|
234
|
|
|
// Moved back over the editing div |
|
235
|
|
|
QuickModifyTopic.prototype.modify_topic_mouseover = function (oEvent) |
|
236
|
|
|
{ |
|
237
|
|
|
this.bMouseOnDiv = true; |
|
238
|
|
|
oEvent.preventDefault(); |
|
239
|
|
|
}; |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* QuickReply object, this allows for selecting the quote button and |
|
243
|
|
|
* having the quote appear in the quick reply box |
|
244
|
|
|
* |
|
245
|
|
|
* @param {type} oOptions |
|
246
|
|
|
*/ |
|
247
|
|
|
function QuickReply(oOptions) |
|
248
|
|
|
{ |
|
249
|
|
|
this.opt = oOptions; |
|
250
|
|
|
this.bCollapsed = this.opt.bDefaultCollapsed; |
|
251
|
|
|
this.bIsFull = this.opt.bIsFull; |
|
252
|
|
|
|
|
253
|
|
|
// If the initial state is to be collapsed, collapse it. |
|
254
|
|
|
if (this.bCollapsed) |
|
255
|
|
|
this.swap(true); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
// When a user presses quote, put it in the quick reply box (if expanded). |
|
259
|
|
|
QuickReply.prototype.quote = function (iMessageId, xDeprecated) |
|
260
|
|
|
{ |
|
261
|
|
|
ajax_indicator(true); |
|
262
|
|
|
|
|
263
|
|
|
// Collapsed on a quote, then simply got to the full post screen |
|
264
|
|
|
if (this.bCollapsed) |
|
265
|
|
|
{ |
|
266
|
|
|
window.location.href = elk_prepareScriptUrl(this.opt.sScriptUrl) + 'action=post;quote=' + iMessageId + ';topic=' + this.opt.iTopicId + '.' + this.opt.iStart; |
|
267
|
|
|
return false; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
// Insert the quote |
|
271
|
|
|
if (this.bIsFull) |
|
272
|
|
|
insertQuoteFast(iMessageId); |
|
273
|
|
|
else |
|
274
|
|
|
getXMLDocument(elk_prepareScriptUrl(this.opt.sScriptUrl) + 'action=quotefast;quote=' + iMessageId + ';xml', this.onQuoteReceived); |
|
275
|
|
|
|
|
276
|
|
|
// Move the view to the quick reply box. |
|
277
|
|
|
if (navigator.appName === 'Microsoft Internet Explorer') |
|
278
|
|
|
window.location.hash = this.opt.sJumpAnchor; |
|
279
|
|
|
else |
|
280
|
|
|
window.location.hash = '#' + this.opt.sJumpAnchor; |
|
281
|
|
|
|
|
282
|
|
|
return false; |
|
283
|
|
|
}; |
|
284
|
|
|
|
|
285
|
|
|
// This is the callback function used after the XMLhttp request. |
|
286
|
|
|
QuickReply.prototype.onQuoteReceived = function (oXMLDoc) |
|
287
|
|
|
{ |
|
288
|
|
|
var sQuoteText = ''; |
|
289
|
|
|
|
|
290
|
|
|
for (var i = 0; i < oXMLDoc.getElementsByTagName('quote')[0].childNodes.length; i++) |
|
291
|
|
|
sQuoteText += oXMLDoc.getElementsByTagName('quote')[0].childNodes[i].nodeValue; |
|
292
|
|
|
|
|
293
|
|
|
replaceText(sQuoteText, document.forms.postmodify.message); |
|
294
|
|
|
|
|
295
|
|
|
ajax_indicator(false); |
|
296
|
|
|
}; |
|
297
|
|
|
|
|
298
|
|
|
// The function handling the swapping of the quick reply area |
|
299
|
|
|
QuickReply.prototype.swap = function (bInit, bSavestate) |
|
300
|
|
|
{ |
|
301
|
|
|
var oQuickReplyContainer = document.getElementById(this.opt.sClassId), |
|
302
|
|
|
sEditorId = this.opt.sContainerId, |
|
303
|
|
|
bIsFull = this.opt.bIsFull; |
|
304
|
|
|
|
|
305
|
|
|
// Default bInit to false and bSavestate to true |
|
306
|
|
|
bInit = typeof(bInit) !== 'undefined'; |
|
307
|
|
|
bSavestate = typeof(bSavestate) === 'undefined'; |
|
308
|
|
|
|
|
309
|
|
|
// Flip our current state if not responding to an initial loading |
|
310
|
|
|
if (!bInit) |
|
311
|
|
|
this.bCollapsed = !this.bCollapsed; |
|
312
|
|
|
|
|
313
|
|
|
// Swap the class on the expcol image as needed |
|
314
|
|
|
var sTargetClass = !this.bCollapsed ? this.opt.sClassCollapsed : this.opt.sClassExpanded; |
|
315
|
|
|
if (oQuickReplyContainer.className !== sTargetClass) |
|
316
|
|
|
oQuickReplyContainer.className = sTargetClass; |
|
317
|
|
|
|
|
318
|
|
|
// And show the new title |
|
319
|
|
|
oQuickReplyContainer.title = oQuickReplyContainer.title = this.bCollapsed ? this.opt.sTitleCollapsed : this.opt.sTitleExpanded; |
|
320
|
|
|
|
|
321
|
|
|
// Show or hide away |
|
322
|
|
|
if (this.bCollapsed) |
|
323
|
|
|
$('#' + this.opt.sContainerId).slideUp(); |
|
324
|
|
|
else |
|
325
|
|
|
{ |
|
326
|
|
|
$('#' + this.opt.sContainerId).slideDown(); |
|
327
|
|
|
if (bIsFull) |
|
328
|
|
|
$('#' + sEditorId).resize(); |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
// Using a cookie for guests? |
|
332
|
|
|
if (bSavestate && 'oCookieOptions' in this.opt && this.opt.oCookieOptions.bUseCookie) |
|
333
|
|
|
this.oCookie.set(this.opt.oCookieOptions.sCookieName, this.bCollapsed ? '1' : '0'); |
|
334
|
|
|
|
|
335
|
|
|
// Save the expand /collapse preference |
|
336
|
|
|
if (!bInit && bSavestate && 'oThemeOptions' in this.opt && this.opt.oThemeOptions.bUseThemeSettings) |
|
337
|
|
|
elk_setThemeOption(this.opt.oThemeOptions.sOptionName, this.bCollapsed ? '1' : '0', 'sThemeId' in this.opt.oThemeOptions ? this.opt.oThemeOptions.sThemeId : null, 'sAdditionalVars' in this.opt.oThemeOptions ? this.opt.oThemeOptions.sAdditionalVars : null); |
|
338
|
|
|
}; |
|
339
|
|
|
|
|
340
|
|
|
/** |
|
341
|
|
|
* QuickModify object. |
|
342
|
|
|
* This will allow for the quick editing of a post via ajax |
|
343
|
|
|
* |
|
344
|
|
|
* @param {object} oOptions |
|
345
|
|
|
*/ |
|
346
|
|
|
function QuickModify(oOptions) |
|
347
|
|
|
{ |
|
348
|
|
|
this.opt = oOptions; |
|
349
|
|
|
this.bInEditMode = false; |
|
350
|
|
|
this.sCurMessageId = ''; |
|
351
|
|
|
this.oCurMessageDiv = null; |
|
352
|
|
|
this.oCurInfoDiv = null; |
|
353
|
|
|
this.oCurSubjectDiv = null; |
|
354
|
|
|
this.oMsgIcon = null; |
|
355
|
|
|
this.sMessageBuffer = ''; |
|
356
|
|
|
this.sSubjectBuffer = ''; |
|
357
|
|
|
this.sInfoBuffer = ''; |
|
358
|
|
|
this.aAccessKeys = []; |
|
359
|
|
|
|
|
360
|
|
|
// Show the edit buttons |
|
361
|
|
|
var aShowQuickModify = document.getElementsByClassName(this.opt.sClassName); |
|
362
|
|
|
for (var i = 0, length = aShowQuickModify.length; i < length; i++) |
|
363
|
|
|
aShowQuickModify[i].style.display = "inline"; |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
// Function called when a user presses the edit button. |
|
367
|
|
|
QuickModify.prototype.modifyMsg = function (iMessageId) |
|
368
|
|
|
{ |
|
369
|
|
|
// Removes the accesskeys from the quickreply inputs and saves them in an array to use them later |
|
370
|
|
|
if (typeof(this.opt.sFormRemoveAccessKeys) !== 'undefined') |
|
371
|
|
|
{ |
|
372
|
|
|
if (typeof(document.forms[this.opt.sFormRemoveAccessKeys])) |
|
373
|
|
|
{ |
|
374
|
|
|
var aInputs = document.forms[this.opt.sFormRemoveAccessKeys].getElementsByTagName('input'); |
|
375
|
|
|
for (var i = 0; i < aInputs.length; i++) |
|
376
|
|
|
{ |
|
377
|
|
|
if (aInputs[i].accessKey !== '') |
|
378
|
|
|
{ |
|
379
|
|
|
this.aAccessKeys[aInputs[i].name] = aInputs[i].accessKey; |
|
380
|
|
|
aInputs[i].accessKey = ''; |
|
381
|
|
|
} |
|
382
|
|
|
} |
|
383
|
|
|
} |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
// First cancel if there's another message still being edited. |
|
387
|
|
|
if (this.bInEditMode) |
|
388
|
|
|
this.modifyCancel(); |
|
389
|
|
|
|
|
390
|
|
|
// At least NOW we're in edit mode |
|
391
|
|
|
this.bInEditMode = true; |
|
392
|
|
|
|
|
393
|
|
|
// Send out the XMLhttp request to get more info |
|
394
|
|
|
ajax_indicator(true); |
|
395
|
|
|
sendXMLDocument.call(this, elk_prepareScriptUrl(elk_scripturl) + 'action=quotefast;quote=' + iMessageId + ';modify;xml', '', this.onMessageReceived); |
|
396
|
|
|
}; |
|
397
|
|
|
|
|
398
|
|
|
// The callback function used for the XMLhttp request retrieving the message. |
|
399
|
|
|
QuickModify.prototype.onMessageReceived = function (XMLDoc) |
|
400
|
|
|
{ |
|
401
|
|
|
var sBodyText = '', |
|
402
|
|
|
sSubjectText; |
|
403
|
|
|
|
|
404
|
|
|
// No longer show the 'loading...' sign. |
|
405
|
|
|
ajax_indicator(false); |
|
406
|
|
|
|
|
407
|
|
|
// Grab the message ID. |
|
408
|
|
|
this.sCurMessageId = XMLDoc.getElementsByTagName('message')[0].getAttribute('id'); |
|
409
|
|
|
|
|
410
|
|
|
// Show the message icon if it was hidden and its set |
|
411
|
|
|
if (this.opt.sIconHide !== null) |
|
412
|
|
|
{ |
|
413
|
|
|
this.oMsgIcon = document.getElementById('messageicon_' + this.sCurMessageId.replace("msg_", "")); |
|
414
|
|
|
if (this.oMsgIcon !== null && getComputedStyle(this.oMsgIcon).getPropertyValue("display") === 'none') |
|
415
|
|
|
this.oMsgIcon.style.display = 'inline'; |
|
416
|
|
|
} |
|
417
|
|
|
|
|
418
|
|
|
// If this is not valid then simply give up. |
|
419
|
|
|
if (!document.getElementById(this.sCurMessageId)) |
|
420
|
|
|
return this.modifyCancel(); |
|
421
|
|
|
|
|
422
|
|
|
// Replace the body part. |
|
423
|
|
|
for (var i = 0; i < XMLDoc.getElementsByTagName("message")[0].childNodes.length; i++) |
|
424
|
|
|
sBodyText += XMLDoc.getElementsByTagName("message")[0].childNodes[i].nodeValue; |
|
425
|
|
|
|
|
426
|
|
|
this.oCurMessageDiv = document.getElementById(this.sCurMessageId); |
|
427
|
|
|
this.sMessageBuffer = this.oCurMessageDiv.innerHTML; |
|
428
|
|
|
|
|
429
|
|
|
// We have to force the body to lose its dollar signs thanks to IE. |
|
430
|
|
|
sBodyText = sBodyText.replace(/\$/g, '{&dollarfix;$}'); |
|
431
|
|
|
|
|
432
|
|
|
// Actually create the content, with a bodge for disappearing dollar signs. |
|
433
|
|
|
this.oCurMessageDiv.innerHTML = this.opt.sTemplateBodyEdit.replace(/%msg_id%/g, this.sCurMessageId.substr(4)).replace(/%body%/, sBodyText).replace(/\{&dollarfix;\$\}/g, '$'); |
|
434
|
|
|
|
|
435
|
|
|
// Save and hide the existing subject div |
|
436
|
|
|
if (this.opt.sIDSubject !== null) |
|
437
|
|
|
{ |
|
438
|
|
|
this.oCurSubjectDiv = document.getElementById(this.opt.sIDSubject + this.sCurMessageId.substr(4)); |
|
439
|
|
|
if (this.oCurSubjectDiv !== null) |
|
440
|
|
|
{ |
|
441
|
|
|
this.oCurSubjectDiv.style.display = 'none'; |
|
442
|
|
|
this.sSubjectBuffer = this.oCurSubjectDiv.innerHTML; |
|
443
|
|
|
} |
|
444
|
|
|
} |
|
445
|
|
|
|
|
446
|
|
|
// Save the info div, then open an input field on it |
|
447
|
|
|
sSubjectText = XMLDoc.getElementsByTagName('subject')[0].childNodes[0].nodeValue.replace(/\$/g, '{&dollarfix;$}'); |
|
448
|
|
|
if (this.opt.sIDInfo !== null) |
|
449
|
|
|
{ |
|
450
|
|
|
this.oCurInfoDiv = document.getElementById(this.opt.sIDInfo + this.sCurMessageId.substr(4)); |
|
451
|
|
|
if (this.oCurInfoDiv !== null) |
|
452
|
|
|
{ |
|
453
|
|
|
this.sInfoBuffer = this.oCurInfoDiv.innerHTML; |
|
454
|
|
|
this.oCurInfoDiv.innerHTML = this.opt.sTemplateSubjectEdit.replace(/%subject%/, sSubjectText).replace(/\{&dollarfix;\$\}/g, '$'); |
|
455
|
|
|
} |
|
456
|
|
|
} |
|
457
|
|
|
|
|
458
|
|
|
// Position the editor in the window |
|
459
|
|
|
location.hash = '#info_' + this.sCurMessageId.substr(this.sCurMessageId.lastIndexOf("_") + 1); |
|
460
|
|
|
|
|
461
|
|
|
// Handle custom function hook before showing the new select. |
|
462
|
|
|
if ('funcOnAfterCreate' in this.opt) |
|
463
|
|
|
{ |
|
464
|
|
|
this.tmpMethod = this.opt.funcOnAfterCreate; |
|
465
|
|
|
this.tmpMethod(this); |
|
466
|
|
|
delete this.tmpMethod; |
|
467
|
|
|
} |
|
468
|
|
|
|
|
469
|
|
|
return true; |
|
470
|
|
|
}; |
|
471
|
|
|
|
|
472
|
|
|
// Function in case the user presses cancel (or other circumstances cause it). |
|
473
|
|
|
QuickModify.prototype.modifyCancel = function () |
|
474
|
|
|
{ |
|
475
|
|
|
// Roll back the HTML to its original state. |
|
476
|
|
|
if (this.oCurMessageDiv) |
|
477
|
|
|
{ |
|
478
|
|
|
this.oCurMessageDiv.innerHTML = this.sMessageBuffer; |
|
479
|
|
|
this.oCurInfoDiv.innerHTML = this.sInfoBuffer; |
|
480
|
|
|
this.oCurSubjectDiv.innerHTML = this.sSubjectBuffer; |
|
481
|
|
|
if (this.oCurSubjectDiv !== null) |
|
482
|
|
|
{ |
|
483
|
|
|
this.oCurSubjectDiv.style.display = ''; |
|
484
|
|
|
} |
|
485
|
|
|
} |
|
486
|
|
|
|
|
487
|
|
|
// Hide the message icon if we are doing that |
|
488
|
|
|
if (this.opt.sIconHide) |
|
489
|
|
|
{ |
|
490
|
|
|
var oCurrentMsgIcon = document.getElementById('msg_icon_' + this.sCurMessageId.replace("msg_", "")); |
|
491
|
|
|
|
|
492
|
|
|
if (oCurrentMsgIcon !== null && oCurrentMsgIcon.src.indexOf(this.opt.sIconHide) > 0) |
|
493
|
|
|
this.oMsgIcon.style.display = 'none'; |
|
494
|
|
|
} |
|
495
|
|
|
|
|
496
|
|
|
// No longer in edit mode, that's right. |
|
497
|
|
|
this.bInEditMode = false; |
|
498
|
|
|
|
|
499
|
|
|
// Let's put back the accesskeys to their original place |
|
500
|
|
|
if (typeof(this.opt.sFormRemoveAccessKeys) !== 'undefined') |
|
501
|
|
|
{ |
|
502
|
|
|
if (typeof(document.forms[this.opt.sFormRemoveAccessKeys])) |
|
503
|
|
|
{ |
|
504
|
|
|
var aInputs = document.forms[this.opt.sFormRemoveAccessKeys].getElementsByTagName('input'); |
|
505
|
|
|
for (var i = 0; i < aInputs.length; i++) |
|
506
|
|
|
{ |
|
507
|
|
|
if (typeof(this.aAccessKeys[aInputs[i].name]) !== 'undefined') |
|
508
|
|
|
{ |
|
509
|
|
|
aInputs[i].accessKey = this.aAccessKeys[aInputs[i].name]; |
|
510
|
|
|
} |
|
511
|
|
|
} |
|
512
|
|
|
} |
|
513
|
|
|
} |
|
514
|
|
|
|
|
515
|
|
|
return false; |
|
516
|
|
|
}; |
|
517
|
|
|
|
|
518
|
|
|
// The function called after a user wants to save his precious message. |
|
519
|
|
|
QuickModify.prototype.modifySave = function (sSessionId, sSessionVar) |
|
520
|
|
|
{ |
|
521
|
|
|
var i = 0, |
|
522
|
|
|
x = [], |
|
523
|
|
|
uIds = []; |
|
524
|
|
|
|
|
525
|
|
|
// We cannot save if we weren't in edit mode. |
|
526
|
|
|
if (!this.bInEditMode) |
|
527
|
|
|
return true; |
|
528
|
|
|
|
|
529
|
|
|
this.bInEditMode = false; |
|
530
|
|
|
|
|
531
|
|
|
// Let's put back the accesskeys to their original place |
|
532
|
|
|
if (typeof(this.opt.sFormRemoveAccessKeys) !== 'undefined') |
|
533
|
|
|
{ |
|
534
|
|
|
if (typeof(document.forms[this.opt.sFormRemoveAccessKeys])) |
|
535
|
|
|
{ |
|
536
|
|
|
var aInputs = document.forms[this.opt.sFormRemoveAccessKeys].getElementsByTagName('input'); |
|
537
|
|
|
for (i = 0; i < aInputs.length; i++) |
|
538
|
|
|
{ |
|
539
|
|
|
if (typeof(this.aAccessKeys[aInputs[i].name]) !== 'undefined') |
|
540
|
|
|
{ |
|
541
|
|
|
aInputs[i].accessKey = this.aAccessKeys[aInputs[i].name]; |
|
542
|
|
|
} |
|
543
|
|
|
} |
|
544
|
|
|
} |
|
545
|
|
|
} |
|
546
|
|
|
|
|
547
|
|
|
var oInputs = document.forms.quickModForm.getElementsByTagName('input'); |
|
548
|
|
|
for (i = 0; i < oInputs.length; i++) |
|
549
|
|
|
{ |
|
550
|
|
|
if (oInputs[i].name === 'uid[]') |
|
551
|
|
|
{ |
|
552
|
|
|
uIds.push('uid[' + i + ']=' + parseInt(oInputs[i].value)); |
|
553
|
|
|
} |
|
554
|
|
|
} |
|
555
|
|
|
|
|
556
|
|
|
x[x.length] = 'subject=' + document.forms.quickModForm.subject.value.replace(/&#/g, "&#").php_urlencode(); |
|
557
|
|
|
x[x.length] = 'message=' + document.forms.quickModForm.message.value.replace(/&#/g, "&#").php_urlencode(); |
|
558
|
|
|
x[x.length] = 'topic=' + parseInt(document.forms.quickModForm.elements.topic.value); |
|
559
|
|
|
x[x.length] = 'msg=' + parseInt(document.forms.quickModForm.elements.msg.value); |
|
560
|
|
|
if (uIds.length > 0) |
|
561
|
|
|
x[x.length] = uIds.join("&"); |
|
562
|
|
|
|
|
563
|
|
|
// Send in the XMLhttp request and let's hope for the best. |
|
564
|
|
|
ajax_indicator(true); |
|
565
|
|
|
sendXMLDocument.call(this, elk_prepareScriptUrl(this.opt.sScriptUrl) + "action=jsmodify;topic=" + this.opt.iTopicId + ";" + elk_session_var + "=" + elk_session_id + ";xml", x.join("&"), this.onModifyDone); |
|
566
|
|
|
|
|
567
|
|
|
return false; |
|
568
|
|
|
}; |
|
569
|
|
|
|
|
570
|
|
|
// Callback function of the XMLhttp request sending the modified message. |
|
571
|
|
|
QuickModify.prototype.onModifyDone = function (XMLDoc) |
|
572
|
|
|
{ |
|
573
|
|
|
var oErrordiv; |
|
574
|
|
|
|
|
575
|
|
|
// We've finished the loading stuff. |
|
576
|
|
|
ajax_indicator(false); |
|
577
|
|
|
|
|
578
|
|
|
// If we didn't get a valid document, just cancel. |
|
579
|
|
|
if (!XMLDoc || !XMLDoc.getElementsByTagName('elk')[0]) |
|
580
|
|
|
{ |
|
581
|
|
|
// Mozilla will nicely tell us what's wrong. |
|
582
|
|
|
if (typeof XMLDoc.childNodes !== 'undefined' && XMLDoc.childNodes.length > 0 && XMLDoc.firstChild.nodeName === 'parsererror') |
|
583
|
|
|
{ |
|
584
|
|
|
oErrordiv = document.getElementById('error_box'); |
|
585
|
|
|
oErrordiv.innerHTML = XMLDoc.firstChild.textContent; |
|
586
|
|
|
oErrordiv.style.display = ''; |
|
587
|
|
|
} |
|
588
|
|
|
else |
|
589
|
|
|
this.modifyCancel(); |
|
590
|
|
|
return; |
|
591
|
|
|
} |
|
592
|
|
|
|
|
593
|
|
|
var message = XMLDoc.getElementsByTagName('elk')[0].getElementsByTagName('message')[0], |
|
594
|
|
|
body = message.getElementsByTagName('body')[0], |
|
595
|
|
|
error = message.getElementsByTagName('error')[0]; |
|
596
|
|
|
|
|
597
|
|
|
$(document.forms.quickModForm.message).removeClass('border_error'); |
|
598
|
|
|
$(document.forms.quickModForm.subject).removeClass('border_error'); |
|
599
|
|
|
|
|
600
|
|
|
if (body) |
|
601
|
|
|
{ |
|
602
|
|
|
// Show new body. |
|
603
|
|
|
var bodyText = ''; |
|
604
|
|
|
for (var i = 0; i < body.childNodes.length; i++) |
|
605
|
|
|
bodyText += body.childNodes[i].nodeValue; |
|
606
|
|
|
|
|
607
|
|
|
this.sMessageBuffer = this.opt.sTemplateBodyNormal.replace(/%body%/, bodyText.replace(/\$/g, '{&dollarfix;$}')).replace(/\{&dollarfix;\$\}/g,'$'); |
|
608
|
|
|
this.oCurMessageDiv.innerHTML = this.sMessageBuffer; |
|
609
|
|
|
|
|
610
|
|
|
// Show new subject div, update in case it changed |
|
611
|
|
|
var oSubject = message.getElementsByTagName('subject')[0], |
|
612
|
|
|
sSubjectText = oSubject.childNodes[0].nodeValue.replace(/\$/g, '{&dollarfix;$}'); |
|
613
|
|
|
|
|
614
|
|
|
this.sSubjectBuffer = this.opt.sTemplateSubjectNormal.replace(/%subject%/, sSubjectText).replace(/\{&dollarfix;\$\}/g, '$'); |
|
615
|
|
|
this.oCurSubjectDiv.innerHTML = this.sSubjectBuffer; |
|
616
|
|
|
this.oCurSubjectDiv.style.display = ''; |
|
617
|
|
|
|
|
618
|
|
|
// Restore the info bar div |
|
619
|
|
|
this.oCurInfoDiv.innerHTML = this.sInfoBuffer; |
|
620
|
|
|
|
|
621
|
|
|
// Show this message as 'modified on x by y'. |
|
622
|
|
|
if (this.opt.bShowModify) |
|
623
|
|
|
{ |
|
624
|
|
|
var modified_element = document.getElementById('modified_' + this.sCurMessageId.substr(4)); |
|
625
|
|
|
modified_element.innerHTML = message.getElementsByTagName('modified')[0].childNodes[0].nodeValue; |
|
626
|
|
|
|
|
627
|
|
|
// Just in case it's the first time the message is modified and the element is hidden |
|
628
|
|
|
modified_element.style.display = 'block'; |
|
629
|
|
|
} |
|
630
|
|
|
|
|
631
|
|
|
// Hide the icon if we were told to |
|
632
|
|
|
if (this.opt.sIconHide !== null) |
|
633
|
|
|
{ |
|
634
|
|
|
var oCurrentMsgIcon = document.getElementById('msg_icon_' + this.sCurMessageId.replace("msg_", "")); |
|
635
|
|
|
if (oCurrentMsgIcon !== null && oCurrentMsgIcon.src.indexOf(this.opt.sIconHide) > 0) |
|
636
|
|
|
this.oMsgIcon.style.display = 'none'; |
|
637
|
|
|
} |
|
638
|
|
|
|
|
639
|
|
|
// Re embed any video links if the feature is available |
|
640
|
|
|
if ($.isFunction($.fn.linkifyvideo)) |
|
641
|
|
|
$().linkifyvideo(oEmbedtext, this.sCurMessageId); |
|
642
|
|
|
|
|
643
|
|
|
// Hello, Sweetie |
|
644
|
|
|
$('#' + this.sCurMessageId + ' .spoilerheader').click(function(){ |
|
645
|
|
|
$(this).next().children().slideToggle("fast"); |
|
646
|
|
|
}); |
|
647
|
|
|
|
|
648
|
|
|
// Re-Fix code blocks |
|
649
|
|
|
if (typeof elk_codefix === 'function') |
|
650
|
|
|
elk_codefix(); |
|
651
|
|
|
|
|
652
|
|
|
// And pretty the code |
|
653
|
|
|
if (typeof prettyPrint === 'function') |
|
654
|
|
|
prettyPrint(); |
|
655
|
|
|
} |
|
656
|
|
|
else if (error) |
|
657
|
|
|
{ |
|
658
|
|
|
oErrordiv = document.getElementById('error_box'); |
|
659
|
|
|
oErrordiv.innerHTML = error.childNodes[0].nodeValue; |
|
660
|
|
|
oErrordiv.style.display = ''; |
|
661
|
|
|
if (error.getAttribute('in_body') === '1') |
|
662
|
|
|
$(document.forms.quickModForm.message).addClass('border_error'); |
|
663
|
|
|
if (error.getAttribute('in_subject') === '1') |
|
664
|
|
|
$(document.forms.quickModForm.subject).addClass('border_error'); |
|
665
|
|
|
} |
|
666
|
|
|
}; |
|
667
|
|
|
|
|
668
|
|
|
/** |
|
669
|
|
|
* Quick Moderation for the topic view |
|
670
|
|
|
* |
|
671
|
|
|
* @param {type} oOptions |
|
672
|
|
|
*/ |
|
673
|
|
|
function InTopicModeration(oOptions) |
|
674
|
|
|
{ |
|
675
|
|
|
this.opt = oOptions; |
|
676
|
|
|
this.bButtonsShown = false; |
|
677
|
|
|
this.iNumSelected = 0; |
|
678
|
|
|
|
|
679
|
|
|
this.init(); |
|
680
|
|
|
} |
|
681
|
|
|
|
|
682
|
|
|
InTopicModeration.prototype.init = function() |
|
683
|
|
|
{ |
|
684
|
|
|
// Add checkboxes to all the messages. |
|
685
|
|
|
for (var i = 0, n = this.opt.aMessageIds.length; i < n; i++) |
|
686
|
|
|
{ |
|
687
|
|
|
// Create the checkbox. |
|
688
|
|
|
var oCheckbox = document.createElement('input'); |
|
689
|
|
|
|
|
690
|
|
|
oCheckbox.type = 'checkbox'; |
|
691
|
|
|
oCheckbox.className = 'input_check'; |
|
692
|
|
|
oCheckbox.name = 'msgs[]'; |
|
693
|
|
|
oCheckbox.value = this.opt.aMessageIds[i]; |
|
694
|
|
|
oCheckbox.onclick = this.handleClick(oCheckbox).bind(this); |
|
695
|
|
|
|
|
696
|
|
|
// Append it to the container |
|
697
|
|
|
var oCheckboxContainer = document.getElementById(this.opt.sCheckboxContainerMask + this.opt.aMessageIds[i]); |
|
698
|
|
|
oCheckboxContainer.appendChild(oCheckbox); |
|
699
|
|
|
oCheckboxContainer.style.display = ''; |
|
700
|
|
|
} |
|
701
|
|
|
}; |
|
702
|
|
|
|
|
703
|
|
|
// They clicked a checkbox in a message so we show the button options to them |
|
704
|
|
|
InTopicModeration.prototype.handleClick = function(oCheckbox) |
|
705
|
|
|
{ |
|
706
|
|
|
if (!this.bButtonsShown && this.opt.sButtonStripDisplay) |
|
707
|
|
|
{ |
|
708
|
|
|
var oButtonStrip = document.getElementById(this.opt.sButtonStrip), |
|
709
|
|
|
oButtonStripDisplay = document.getElementById(this.opt.sButtonStripDisplay); |
|
710
|
|
|
|
|
711
|
|
|
// Make sure it can go somewhere. |
|
712
|
|
|
if (typeof(oButtonStripDisplay) === 'object' && oButtonStripDisplay !== null) |
|
713
|
|
|
oButtonStripDisplay.style.display = ""; |
|
714
|
|
|
else |
|
715
|
|
|
{ |
|
716
|
|
|
var oNewDiv = document.createElement('div'), |
|
717
|
|
|
oNewList = document.createElement('ul'); |
|
718
|
|
|
|
|
719
|
|
|
oNewDiv.id = this.opt.sButtonStripDisplay; |
|
720
|
|
|
oNewDiv.className = this.opt.sButtonStripClass ? this.opt.sButtonStripClass : 'buttonlist floatbottom'; |
|
721
|
|
|
|
|
722
|
|
|
oNewDiv.appendChild(oNewList); |
|
723
|
|
|
oButtonStrip.appendChild(oNewDiv); |
|
724
|
|
|
} |
|
725
|
|
|
|
|
726
|
|
|
// Add the 'remove selected items' button. |
|
727
|
|
|
if (this.opt.bCanRemove) |
|
728
|
|
|
elk_addButton(this.opt.sButtonStrip, this.opt.bUseImageButton, { |
|
729
|
|
|
sId: 'remove_button', |
|
730
|
|
|
sText: this.opt.sRemoveButtonLabel, |
|
731
|
|
|
sImage: this.opt.sRemoveButtonImage, |
|
732
|
|
|
sUrl: '#', |
|
733
|
|
|
aEvents: [ |
|
734
|
|
|
['click', this.handleSubmit('remove').bind(this) |
|
735
|
|
|
] |
|
736
|
|
|
}); |
|
|
|
|
|
|
737
|
|
|
|
|
738
|
|
|
// Add the 'restore selected items' button. |
|
739
|
|
|
if (this.opt.bCanRestore) |
|
740
|
|
|
elk_addButton(this.opt.sButtonStrip, this.opt.bUseImageButton, { |
|
741
|
|
|
sId: 'restore_button', |
|
742
|
|
|
sText: this.opt.sRestoreButtonLabel, |
|
743
|
|
|
sImage: this.opt.sRestoreButtonImage, |
|
744
|
|
|
sUrl: '#', |
|
745
|
|
|
aEvents: [ |
|
746
|
|
|
['click', this.handleSubmit('restore').bind(this) |
|
747
|
|
|
] |
|
748
|
|
|
}); |
|
|
|
|
|
|
749
|
|
|
|
|
750
|
|
|
// Add the 'split selected items' button. |
|
751
|
|
|
if (this.opt.bCanSplit) |
|
752
|
|
|
elk_addButton(this.opt.sButtonStrip, this.opt.bUseImageButton, { |
|
753
|
|
|
sId: 'split_button', |
|
754
|
|
|
sText: this.opt.sSplitButtonLabel, |
|
755
|
|
|
sImage: this.opt.sSplitButtonImage, |
|
756
|
|
|
sUrl: '#', |
|
757
|
|
|
aEvents: [ |
|
758
|
|
|
['click', this.handleSubmit('split').bind(this) |
|
759
|
|
|
] |
|
760
|
|
|
}); |
|
|
|
|
|
|
761
|
|
|
|
|
762
|
|
|
// Adding these buttons once should be enough. |
|
763
|
|
|
this.bButtonsShown = true; |
|
764
|
|
|
} |
|
765
|
|
|
|
|
766
|
|
|
// Keep stats on how many items were selected. |
|
767
|
|
|
this.iNumSelected += oCheckbox.checked ? 1 : -1; |
|
768
|
|
|
|
|
769
|
|
|
// Show the number of messages selected in each of the buttons. |
|
770
|
|
|
if (this.opt.bCanRemove && !this.opt.bUseImageButton) |
|
771
|
|
|
{ |
|
772
|
|
|
oButtonStrip.getElementById('remove_button_text').innerHTML = this.opt.sRemoveButtonLabel + ' [' + this.iNumSelected + ']'; |
|
|
|
|
|
|
773
|
|
|
oButtonStrip.getElementById('remove_button').style.display = this.iNumSelected < 1 ? "none" : ""; |
|
|
|
|
|
|
774
|
|
|
} |
|
775
|
|
|
|
|
776
|
|
|
if (this.opt.bCanRestore && !this.opt.bUseImageButton) |
|
777
|
|
|
{ |
|
778
|
|
|
oButtonStrip.getElementById('restore_button_text').innerHTML = this.opt.sRestoreButtonLabel + ' [' + this.iNumSelected + ']'; |
|
|
|
|
|
|
779
|
|
|
oButtonStrip.getElementById('restore_button').style.display = this.iNumSelected < 1 ? "none" : ""; |
|
|
|
|
|
|
780
|
|
|
} |
|
781
|
|
|
|
|
782
|
|
|
if (this.opt.bCanSplit && !this.opt.bUseImageButton) |
|
783
|
|
|
{ |
|
784
|
|
|
oButtonStrip.getElementById('split_button_text').innerHTML = this.opt.sSplitButtonLabel + ' [' + this.iNumSelected + ']'; |
|
|
|
|
|
|
785
|
|
|
oButtonStrip.getElementById('split_button').style.display = this.iNumSelected < 1 ? "none" : ""; |
|
|
|
|
|
|
786
|
|
|
} |
|
787
|
|
|
|
|
788
|
|
|
// Try to restore the correct position. |
|
789
|
|
|
var aItems = oButtonStrip.getElementsByTagName('span'); |
|
|
|
|
|
|
790
|
|
|
if (aItems.length > 3) |
|
791
|
|
|
{ |
|
792
|
|
|
if (this.iNumSelected < 1) |
|
793
|
|
|
{ |
|
794
|
|
|
aItems[aItems.length - 3].className = aItems[aItems.length - 3].className.replace(/\s*position_holder/, 'last'); |
|
795
|
|
|
aItems[aItems.length - 2].className = aItems[aItems.length - 2].className.replace(/\s*position_holder/, 'last'); |
|
796
|
|
|
} |
|
797
|
|
|
else |
|
798
|
|
|
{ |
|
799
|
|
|
aItems[aItems.length - 2].className = aItems[aItems.length - 2].className.replace(/\s*last/, 'position_holder'); |
|
800
|
|
|
aItems[aItems.length - 3].className = aItems[aItems.length - 3].className.replace(/\s*last/, 'position_holder'); |
|
801
|
|
|
} |
|
802
|
|
|
} |
|
803
|
|
|
}; |
|
804
|
|
|
|
|
805
|
|
|
// Called when the user clicks one of the buttons that we added |
|
806
|
|
|
InTopicModeration.prototype.handleSubmit = function (sSubmitType) |
|
807
|
|
|
{ |
|
808
|
|
|
var oForm = document.getElementById(this.opt.sFormId); |
|
809
|
|
|
|
|
810
|
|
|
// Make sure this form isn't submitted in another way than this function. |
|
811
|
|
|
var oInput = document.createElement('input'); |
|
812
|
|
|
|
|
813
|
|
|
oInput.type = 'hidden'; |
|
814
|
|
|
oInput.name = this.opt.sSessionVar; |
|
815
|
|
|
oInput.value = this.opt.sSessionId; |
|
816
|
|
|
oForm.appendChild(oInput); |
|
817
|
|
|
|
|
818
|
|
|
// Set the form action based on the button they clicked |
|
819
|
|
|
switch (sSubmitType) |
|
820
|
|
|
{ |
|
821
|
|
|
case 'remove': |
|
822
|
|
|
if (!confirm(this.opt.sRemoveButtonConfirm)) |
|
823
|
|
|
return false; |
|
824
|
|
|
|
|
825
|
|
|
oForm.action = oForm.action.replace(/;split_selection=1/, ''); |
|
826
|
|
|
oForm.action = oForm.action.replace(/;restore_selected=1/, ''); |
|
827
|
|
|
break; |
|
828
|
|
|
|
|
829
|
|
|
case 'restore': |
|
830
|
|
|
if (!confirm(this.opt.sRestoreButtonConfirm)) |
|
831
|
|
|
return false; |
|
832
|
|
|
|
|
833
|
|
|
oForm.action = oForm.action.replace(/;split_selection=1/, ''); |
|
834
|
|
|
oForm.action += ';restore_selected=1'; |
|
835
|
|
|
break; |
|
836
|
|
|
|
|
837
|
|
|
case 'split': |
|
838
|
|
|
if (!confirm(this.opt.sRestoreButtonConfirm)) |
|
839
|
|
|
return false; |
|
840
|
|
|
|
|
841
|
|
|
oForm.action = oForm.action.replace(/;restore_selected=1/, ''); |
|
842
|
|
|
oForm.action += ';split_selection=1'; |
|
843
|
|
|
break; |
|
844
|
|
|
|
|
845
|
|
|
default: |
|
846
|
|
|
return false; |
|
847
|
|
|
break; |
|
|
|
|
|
|
848
|
|
|
} |
|
849
|
|
|
|
|
850
|
|
|
oForm.submit(); |
|
851
|
|
|
return true; |
|
852
|
|
|
}; |
|
853
|
|
|
|
|
854
|
|
|
|
|
855
|
|
|
/** |
|
856
|
|
|
* Expands an attachment thumbnail when its clicked |
|
857
|
|
|
* |
|
858
|
|
|
* @param {string} thumbID |
|
859
|
|
|
* @param {string} messageID |
|
860
|
|
|
*/ |
|
861
|
|
|
function expandThumbLB(thumbID, messageID) { |
|
862
|
|
|
var link = document.getElementById('link_' + thumbID), |
|
863
|
|
|
siblings = $('a[data-lightboxmessage="' + messageID + '"]'), |
|
864
|
|
|
navigation = [], |
|
865
|
|
|
xDown = null, |
|
866
|
|
|
yDown = null, |
|
867
|
|
|
$elk_expand_icon = $('<span id="elk_lb_expand"></span>'), |
|
868
|
|
|
$elk_lightbox = $('#elk_lightbox'), |
|
869
|
|
|
$elk_lb_content = $('#elk_lb_content'), |
|
870
|
|
|
ajaxIndicatorOn = function () { |
|
871
|
|
|
$('<div id="lightbox-loading"><i class="icon icon-spin icon-xl i-spinner"></i><div>').appendTo($elk_lb_content); |
|
872
|
|
|
$('html, body').addClass('elk_lb_no_scrolling'); |
|
873
|
|
|
}, |
|
874
|
|
|
ajaxIndicatorOff = function () { |
|
875
|
|
|
$('#lightbox-loading').remove(); |
|
876
|
|
|
}, |
|
877
|
|
|
closeLightbox = function () { |
|
878
|
|
|
// Close the lightbox and remove handlers |
|
879
|
|
|
$elk_expand_icon.off('click'); |
|
880
|
|
|
$elk_lightbox.hide(); |
|
881
|
|
|
$elk_lb_content.html('').removeAttr('style').removeClass('expand'); |
|
882
|
|
|
$('html, body').removeClass('elk_lb_no_scrolling'); |
|
883
|
|
|
$(window).off('resize.lb'); |
|
884
|
|
|
$(window).off('keydown.lb'); |
|
885
|
|
|
$(window).off('touchstart.lb'); |
|
886
|
|
|
$(window).off('touchmove.lb'); |
|
887
|
|
|
}, |
|
888
|
|
|
openLightbox = function () { |
|
889
|
|
|
// Load and open an image in the lightbox |
|
890
|
|
|
$('<img id="elk_lb_img" src="' + link.href + '">') |
|
891
|
|
|
.on('load', function () { |
|
892
|
|
|
var screenWidth = (window.innerWidth ? window.innerWidth : $(window).width()) * (is_mobile ? 0.8 : 0.9), |
|
893
|
|
|
screenHeight = (window.innerHeight ? window.innerHeight : $(window).height()) * 0.9; |
|
894
|
|
|
|
|
895
|
|
|
$(this).css({ |
|
896
|
|
|
'max-width': Math.floor(screenWidth) + 'px', |
|
897
|
|
|
'max-height': Math.floor(screenHeight) + 'px' |
|
898
|
|
|
}); |
|
899
|
|
|
|
|
900
|
|
|
$elk_lb_content.html($(this)).append($elk_expand_icon); |
|
901
|
|
|
|
|
902
|
|
|
ajaxIndicatorOff(); |
|
903
|
|
|
}) |
|
904
|
|
|
.on('error', function () { |
|
905
|
|
|
// Perhaps a message, but for now make it look like we tried and failed |
|
906
|
|
|
setTimeout(function () { |
|
907
|
|
|
ajaxIndicatorOff(); |
|
908
|
|
|
closeLightbox(); |
|
909
|
|
|
}, 1500); |
|
910
|
|
|
}); |
|
911
|
|
|
}, |
|
912
|
|
|
nextNav = function () { |
|
913
|
|
|
// Get / Set the next image ID in the array (with wrap around) |
|
914
|
|
|
thumbID = navigation[($.inArray(thumbID, navigation) + 1) % navigation.length]; |
|
915
|
|
|
}, |
|
916
|
|
|
prevNav = function () { |
|
917
|
|
|
// Get / Set the previous image ID in the array (with wrap around) |
|
918
|
|
|
thumbID = navigation[($.inArray(thumbID, navigation) - 1 + navigation.length) % navigation.length]; |
|
919
|
|
|
}, |
|
920
|
|
|
navLightbox = function () { |
|
921
|
|
|
// Navigate to the next image and show it in the lightbox |
|
922
|
|
|
$elk_lb_content.html('').removeAttr('style').removeClass('expand'); |
|
923
|
|
|
ajaxIndicatorOn(); |
|
924
|
|
|
$elk_expand_icon.off('click'); |
|
925
|
|
|
link = document.getElementById('link_' + thumbID); |
|
926
|
|
|
openLightbox(); |
|
927
|
|
|
expandLightbox(); |
|
928
|
|
|
}, |
|
929
|
|
|
expandLightbox = function () { |
|
930
|
|
|
// Add an expand the image to full size when the expand icon is clicked |
|
931
|
|
|
$elk_expand_icon.on('click', function () { |
|
932
|
|
|
$('#elk_lb_content').addClass('expand').css({ |
|
933
|
|
|
'height': Math.floor(window.innerHeight * 0.95) + 'px', |
|
934
|
|
|
'width': Math.floor(window.innerWidth * 0.9) + 'px', |
|
935
|
|
|
'left': '0' |
|
936
|
|
|
}); |
|
937
|
|
|
$('#elk_lb_img').removeAttr('style'); |
|
938
|
|
|
$elk_expand_icon.hide(); |
|
939
|
|
|
$(window).off('keydown.lb'); |
|
940
|
|
|
$(window).off('touchmove.lb'); |
|
941
|
|
|
}); |
|
942
|
|
|
}; |
|
943
|
|
|
|
|
944
|
|
|
// Create the lightbox container only if needed |
|
945
|
|
|
if ($elk_lightbox.length <= 0) { |
|
946
|
|
|
// For easy manipulation |
|
947
|
|
|
$elk_lightbox = $('<div id="elk_lightbox"></div>'); |
|
948
|
|
|
$elk_lb_content = $('<div id="elk_lb_content"></div>'); |
|
949
|
|
|
|
|
950
|
|
|
$('body').append($elk_lightbox.append($elk_lb_content)); |
|
951
|
|
|
} |
|
952
|
|
|
|
|
953
|
|
|
// Load the navigation array |
|
954
|
|
|
siblings.each(function () { |
|
955
|
|
|
navigation[navigation.length] = $(this).data('lightboximage'); |
|
956
|
|
|
}); |
|
957
|
|
|
|
|
958
|
|
|
// We should always have at least the thumbID |
|
959
|
|
|
if (navigation.length === 0) { |
|
960
|
|
|
navigation[navigation.length] = thumbID; |
|
961
|
|
|
} |
|
962
|
|
|
|
|
963
|
|
|
// Load and show the initial lightbox container div |
|
964
|
|
|
ajaxIndicatorOn(); |
|
965
|
|
|
$elk_lightbox.fadeIn(200); |
|
966
|
|
|
openLightbox(); |
|
967
|
|
|
expandLightbox(); |
|
968
|
|
|
|
|
969
|
|
|
// Click anywhere on the page (except the expand icon) to close the lightbox |
|
970
|
|
|
$elk_lightbox.on('click', function (event) { |
|
971
|
|
|
if (event.target.id !== $elk_expand_icon.attr('id')) { |
|
972
|
|
|
event.preventDefault(); |
|
973
|
|
|
closeLightbox(); |
|
974
|
|
|
} |
|
975
|
|
|
}); |
|
976
|
|
|
|
|
977
|
|
|
// Provide some keyboard navigation |
|
978
|
|
|
$(window).on('keydown.lb', function (event) { |
|
979
|
|
|
event.preventDefault(); |
|
980
|
|
|
|
|
981
|
|
|
// escape |
|
982
|
|
|
if (event.keyCode === 27) { |
|
983
|
|
|
closeLightbox(); |
|
984
|
|
|
} |
|
985
|
|
|
|
|
986
|
|
|
// left |
|
987
|
|
|
if (event.keyCode === 37) { |
|
988
|
|
|
prevNav(); |
|
989
|
|
|
navLightbox(); |
|
990
|
|
|
} |
|
991
|
|
|
|
|
992
|
|
|
// right |
|
993
|
|
|
if (event.keyCode === 39) { |
|
994
|
|
|
nextNav(); |
|
995
|
|
|
navLightbox(); |
|
996
|
|
|
} |
|
997
|
|
|
}); |
|
998
|
|
|
|
|
999
|
|
|
// Make the image size fluid as the browser window changes |
|
1000
|
|
|
$(window).on('resize.lb', function () { |
|
1001
|
|
|
// Account for either a normal or expanded view |
|
1002
|
|
|
var $_elk_lb_content = $('#elk_lb_content'); |
|
1003
|
|
|
|
|
1004
|
|
|
if ($_elk_lb_content.hasClass('expand')) |
|
1005
|
|
|
$_elk_lb_content.css({'height': window.innerHeight * 0.85, 'width': window.innerWidth * 0.9}); |
|
1006
|
|
|
else |
|
1007
|
|
|
$('#elk_lb_img').css({'max-height': window.innerHeight * 0.9, 'max-width': window.innerWidth * 0.8}); |
|
1008
|
|
|
}); |
|
1009
|
|
|
|
|
1010
|
|
|
// Swipe navigation start, record press x/y |
|
1011
|
|
|
$(window).on('touchstart.lb', function (event) { |
|
1012
|
|
|
xDown = event.originalEvent.touches[0].clientX; |
|
1013
|
|
|
yDown = event.originalEvent.touches[0].clientY; |
|
1014
|
|
|
}); |
|
1015
|
|
|
|
|
1016
|
|
|
// Swipe navigation left / right detection |
|
1017
|
|
|
$(window).on('touchmove.lb', function(event) { |
|
1018
|
|
|
// No known start point ? |
|
1019
|
|
|
if (!xDown || !yDown) |
|
1020
|
|
|
return; |
|
1021
|
|
|
|
|
1022
|
|
|
// Where are we now |
|
1023
|
|
|
var xUp = event.originalEvent.touches[0].clientX, |
|
1024
|
|
|
yUp = event.originalEvent.touches[0].clientY, |
|
1025
|
|
|
xDiff = xDown - xUp, |
|
1026
|
|
|
yDiff = yDown - yUp; |
|
1027
|
|
|
|
|
1028
|
|
|
// Moved enough to know what direction they are swiping |
|
1029
|
|
|
if (Math.abs(xDiff) > Math.abs(yDiff)) { |
|
1030
|
|
|
if (xDiff > 0) { |
|
1031
|
|
|
// Swipe left |
|
1032
|
|
|
prevNav(); |
|
1033
|
|
|
navLightbox(); |
|
1034
|
|
|
} else { |
|
1035
|
|
|
// Swipe right |
|
1036
|
|
|
nextNav(); |
|
1037
|
|
|
navLightbox(); |
|
1038
|
|
|
} |
|
1039
|
|
|
} |
|
1040
|
|
|
|
|
1041
|
|
|
// Reset values |
|
1042
|
|
|
xDown = null; |
|
1043
|
|
|
yDown = null; |
|
1044
|
|
|
}); |
|
1045
|
|
|
|
|
1046
|
|
|
return false; |
|
1047
|
|
|
} |
|
1048
|
|
|
|
|
1049
|
|
|
/** |
|
1050
|
|
|
* Expands an attachment thumbnail when its clicked |
|
1051
|
|
|
* |
|
1052
|
|
|
* @param {string} thumbID |
|
1053
|
|
|
*/ |
|
1054
|
|
|
function expandThumb(thumbID) |
|
1055
|
|
|
{ |
|
1056
|
|
|
var img = document.getElementById('thumb_' + thumbID), |
|
1057
|
|
|
link = document.getElementById('link_' + thumbID), |
|
1058
|
|
|
name = link.nextSibling; |
|
1059
|
|
|
|
|
1060
|
|
|
// Some browsers will add empty text so loop to the next element node |
|
1061
|
|
|
while (name && name.nodeType !== 1) { |
|
1062
|
|
|
name = name.nextSibling; |
|
1063
|
|
|
} |
|
1064
|
|
|
var details = name.nextSibling; |
|
1065
|
|
|
while (details && details.nodeType !== 1) { |
|
1066
|
|
|
details = details.nextSibling; |
|
1067
|
|
|
} |
|
1068
|
|
|
|
|
1069
|
|
|
// Save the currently displayed image attributes |
|
1070
|
|
|
var tmp_src = img.src, |
|
1071
|
|
|
tmp_height = img.style.height, |
|
1072
|
|
|
tmp_width = img.style.width; |
|
1073
|
|
|
|
|
1074
|
|
|
// Set the displayed image attributes to the link attributes, this will expand in place |
|
1075
|
|
|
img.src = link.href; |
|
1076
|
|
|
img.style.width = link.style.width; |
|
1077
|
|
|
img.style.height = link.style.height; |
|
1078
|
|
|
|
|
1079
|
|
|
// Swap the class name on the title/desc |
|
1080
|
|
|
name.className = name.className.includes('_exp') ? 'attachment_name' : 'attachment_name attachment_name_exp'; |
|
1081
|
|
|
details.className = details.className.includes('_exp') ? 'attachment_details' : 'attachment_details attachment_details_exp'; |
|
1082
|
|
|
|
|
1083
|
|
|
// Now place the image attributes back |
|
1084
|
|
|
link.href = tmp_src; |
|
1085
|
|
|
link.style.width = tmp_width; |
|
1086
|
|
|
link.style.height = tmp_height; |
|
1087
|
|
|
|
|
1088
|
|
|
return false; |
|
1089
|
|
|
} |
|
1090
|
|
|
|
|
1091
|
|
|
/** |
|
1092
|
|
|
* Provides a way to toggle an ignored message(s) visibility |
|
1093
|
|
|
* |
|
1094
|
|
|
* @param {object} msgids |
|
1095
|
|
|
* @param {string} text |
|
1096
|
|
|
*/ |
|
1097
|
|
|
function ignore_toggles(msgids, text) |
|
1098
|
|
|
{ |
|
1099
|
|
|
for (var i = 0; i < msgids.length; i++) |
|
1100
|
|
|
{ |
|
1101
|
|
|
var msgid = msgids[i]; |
|
1102
|
|
|
|
|
1103
|
|
|
var discard = new elk_Toggle({ |
|
1104
|
|
|
bToggleEnabled: true, |
|
1105
|
|
|
bCurrentlyCollapsed: true, |
|
1106
|
|
|
aSwappableContainers: [ |
|
1107
|
|
|
'msg_' + msgid + '_extra_info', |
|
1108
|
|
|
'msg_' + msgid, |
|
1109
|
|
|
'msg_' + msgid + '_footer', |
|
1110
|
|
|
'msg_' + msgid + '_quick_mod', |
|
1111
|
|
|
'modify_button_' + msgid, |
|
1112
|
|
|
'msg_' + msgid + '_signature' |
|
1113
|
|
|
], |
|
1114
|
|
|
aSwapLinks: [ |
|
1115
|
|
|
{ |
|
1116
|
|
|
sId: 'msg_' + msgid + '_ignored_link', |
|
1117
|
|
|
msgExpanded: '', |
|
1118
|
|
|
msgCollapsed: text |
|
1119
|
|
|
} |
|
1120
|
|
|
] |
|
1121
|
|
|
}); |
|
1122
|
|
|
} |
|
1123
|
|
|
} |
|
1124
|
|
|
|
|
1125
|
|
|
/** |
|
1126
|
|
|
* Open the sendtopic overlay div |
|
1127
|
|
|
* @todo make these... "things" look nice |
|
1128
|
|
|
* |
|
1129
|
|
|
* @param {type} desktopURL |
|
1130
|
|
|
* @param {type} sHeader |
|
1131
|
|
|
* @param {type} sIcon |
|
1132
|
|
|
*/ |
|
1133
|
|
|
function sendtopicOverlayDiv(desktopURL, sHeader, sIcon) |
|
1134
|
|
|
{ |
|
1135
|
|
|
// Set up our div details |
|
1136
|
|
|
var sAjax_indicator = '<div class="centertext"><i class="icon icon-spin i-spinner"></i></div>', |
|
1137
|
|
|
oPopup_body; |
|
1138
|
|
|
|
|
1139
|
|
|
// TODO: Even if we weren't purging icons, this is still not the right icon for this. |
|
1140
|
|
|
sIcon = typeof(sIcon) === 'string' ? sIcon : 'i-envelope'; |
|
1141
|
|
|
sHeader = typeof(sHeader) === 'string' ? sHeader : help_popup_heading_text; |
|
1142
|
|
|
|
|
1143
|
|
|
// Load the send topic overlay div |
|
1144
|
|
|
$.ajax({ |
|
1145
|
|
|
url: desktopURL, |
|
1146
|
|
|
type: "GET", |
|
1147
|
|
|
dataType: "html" |
|
1148
|
|
|
}) |
|
1149
|
|
|
.done(function (data) { |
|
1150
|
|
|
var $base_obj = $('<div id="temp_help">').html(data).find('#send_topic'), |
|
1151
|
|
|
title = ''; |
|
1152
|
|
|
|
|
1153
|
|
|
$base_obj.find('h3').each(function () { |
|
1154
|
|
|
title = $(this).text(); |
|
1155
|
|
|
$(this).remove(); |
|
1156
|
|
|
}); |
|
1157
|
|
|
|
|
1158
|
|
|
var form = $base_obj.find('form'), |
|
1159
|
|
|
url = $base_obj.find('form').attr('action'); |
|
1160
|
|
|
|
|
1161
|
|
|
// Create the div that we are going to load |
|
1162
|
|
|
var oContainer = new smc_Popup({heading: (title !== '' ? title : sHeader), content: sAjax_indicator, icon: sIcon}); |
|
1163
|
|
|
oPopup_body = $('#' + oContainer.popup_id).find('.popup_content'); |
|
1164
|
|
|
oPopup_body.html($base_obj.html()); |
|
1165
|
|
|
|
|
1166
|
|
|
// Tweak the width of the popup for this special window |
|
1167
|
|
|
$('.popup_window').css({'width': '640px'}); |
|
1168
|
|
|
|
|
1169
|
|
|
sendtopicForm(oPopup_body, url, oContainer); |
|
1170
|
|
|
}) |
|
1171
|
|
|
.fail(function (xhr, textStatus, errorThrown) { |
|
1172
|
|
|
oPopup_body.html(textStatus); |
|
1173
|
|
|
}); |
|
1174
|
|
|
|
|
1175
|
|
|
return false; |
|
1176
|
|
|
} |
|
1177
|
|
|
|
|
1178
|
|
|
/** |
|
1179
|
|
|
* Helper function for sendtopicForm, highlights missing fields that must |
|
1180
|
|
|
* be filled in in order to send the topic |
|
1181
|
|
|
* |
|
1182
|
|
|
* @param {type} $this_form |
|
1183
|
|
|
* @param {string} classname |
|
1184
|
|
|
* @param {boolean} focused |
|
1185
|
|
|
*/ |
|
1186
|
|
|
function addRequiredElem($this_form, classname, focused) |
|
1187
|
|
|
{ |
|
1188
|
|
|
if (typeof(focused) === 'undefined') |
|
1189
|
|
|
focused = false; |
|
1190
|
|
|
|
|
1191
|
|
|
$this_form.find('input[name="' + classname + '"]').after($('<span class="requiredfield" />').text(required_field).fadeIn()); |
|
1192
|
|
|
$this_form.find('input[name="' + classname + '"]').keyup(function () { |
|
1193
|
|
|
$this_form.find('.' + classname + ' .requiredfield').fadeOut(function () { |
|
1194
|
|
|
$(this).remove(); |
|
1195
|
|
|
}); |
|
1196
|
|
|
}); |
|
1197
|
|
|
|
|
1198
|
|
|
if (!focused) |
|
1199
|
|
|
{ |
|
1200
|
|
|
$this_form.find('input[name="' + classname + '"]').focus(); |
|
1201
|
|
|
focused = true; |
|
1202
|
|
|
} |
|
1203
|
|
|
} |
|
1204
|
|
|
|
|
1205
|
|
|
/** |
|
1206
|
|
|
* Send in the send topic form |
|
1207
|
|
|
* |
|
1208
|
|
|
* @param {object} oPopup_body |
|
1209
|
|
|
* @param {string} url |
|
1210
|
|
|
* @param {object} oContainer |
|
1211
|
|
|
*/ |
|
1212
|
|
|
function sendtopicForm(oPopup_body, url, oContainer) |
|
1213
|
|
|
{ |
|
1214
|
|
|
if (typeof(this_body) !== 'undefined') |
|
1215
|
|
|
oPopup_body.html(this_body); |
|
1216
|
|
|
|
|
1217
|
|
|
var $this_form = $(oPopup_body).find('form'); |
|
1218
|
|
|
|
|
1219
|
|
|
if (typeof(send_comment) !== 'undefined') |
|
1220
|
|
|
{ |
|
1221
|
|
|
$this_form.find('input[name="comment"]').val(send_comment); |
|
1222
|
|
|
$this_form.find('input[name="y_name"]').val(sender_name); |
|
1223
|
|
|
$this_form.find('input[name="y_email"]').val(sender_mail); |
|
1224
|
|
|
$this_form.find('input[name="r_name"]').val(recipient_name); |
|
1225
|
|
|
$this_form.find('input[name="r_email"]').val(recipient_mail); |
|
1226
|
|
|
} |
|
1227
|
|
|
|
|
1228
|
|
|
oPopup_body.find('input[name="send"]').on('click', function (event) { |
|
1229
|
|
|
event.preventDefault(); |
|
1230
|
|
|
|
|
1231
|
|
|
var data = $this_form.serialize() + '&send=1', |
|
1232
|
|
|
sender_name = $this_form.find('input[name="y_name"]').val(), |
|
1233
|
|
|
sender_mail = $this_form.find('input[name="y_email"]').val, |
|
1234
|
|
|
recipient_name = $this_form.find('input[name="r_name"]').val(), |
|
1235
|
|
|
recipient_mail = $this_form.find('input[name="r_email"]').val(), |
|
1236
|
|
|
missing_elems = false; |
|
1237
|
|
|
|
|
1238
|
|
|
// Check for any input fields that were not filled in |
|
1239
|
|
|
if (sender_name === '') |
|
1240
|
|
|
{ |
|
1241
|
|
|
addRequiredElem($this_form, 'y_name', missing_elems); |
|
1242
|
|
|
missing_elems = true; |
|
1243
|
|
|
} |
|
1244
|
|
|
|
|
1245
|
|
|
if (sender_mail === '') |
|
1246
|
|
|
{ |
|
1247
|
|
|
addRequiredElem($this_form, 'y_email', missing_elems); |
|
1248
|
|
|
missing_elems = true; |
|
1249
|
|
|
} |
|
1250
|
|
|
|
|
1251
|
|
|
if (recipient_name === '') |
|
1252
|
|
|
{ |
|
1253
|
|
|
addRequiredElem($this_form, 'r_name', missing_elems); |
|
1254
|
|
|
missing_elems = true; |
|
1255
|
|
|
} |
|
1256
|
|
|
|
|
1257
|
|
|
if (recipient_mail === '') |
|
1258
|
|
|
{ |
|
1259
|
|
|
addRequiredElem($this_form, 'r_email', missing_elems); |
|
1260
|
|
|
missing_elems = true; |
|
1261
|
|
|
} |
|
1262
|
|
|
|
|
1263
|
|
|
// Missing required elements, back we go |
|
1264
|
|
|
if (missing_elems) |
|
1265
|
|
|
return; |
|
1266
|
|
|
|
|
1267
|
|
|
// Send it to the server to validate the input |
|
1268
|
|
|
$.ajax({ |
|
1269
|
|
|
type: 'post', |
|
1270
|
|
|
url: url + ';api', |
|
1271
|
|
|
data: data |
|
1272
|
|
|
}) |
|
1273
|
|
|
.done(function (request) { |
|
1274
|
|
|
var oElement = $(request).find('elk')[0], |
|
1275
|
|
|
text = null; |
|
1276
|
|
|
|
|
1277
|
|
|
// No errors in the response, lets say it sent. |
|
1278
|
|
|
if (oElement.getElementsByTagName('error').length === 0) |
|
1279
|
|
|
{ |
|
1280
|
|
|
text = oElement.getElementsByTagName('text')[0].firstChild.nodeValue.removeEntities(); |
|
1281
|
|
|
text += '<br /><br /><input type="submit" name="send" value="' + sendtopic_back + '" class="button_submit"/><input type="submit" name="cancel" value="' + sendtopic_close + '" class="button_submit"/>'; |
|
1282
|
|
|
|
|
1283
|
|
|
oPopup_body.html(text); |
|
1284
|
|
|
|
|
1285
|
|
|
// Setup the cancel button to end this entire process |
|
1286
|
|
|
oPopup_body.find('input[name="cancel"]').each(function () { |
|
1287
|
|
|
$(this).on('click', function (event) { |
|
1288
|
|
|
event.preventDefault(); |
|
1289
|
|
|
oContainer.hide(); |
|
1290
|
|
|
}); |
|
1291
|
|
|
}); |
|
1292
|
|
|
} |
|
1293
|
|
|
// Invalid data in the form, like a bad email etc, show the message text |
|
1294
|
|
|
else |
|
1295
|
|
|
{ |
|
1296
|
|
|
if (oElement.getElementsByTagName('text').length !== 0) |
|
1297
|
|
|
{ |
|
1298
|
|
|
text = oElement.getElementsByTagName('text')[0].firstChild.nodeValue.removeEntities(); |
|
1299
|
|
|
text += '<br /><br /><input type="submit" name="send" value="' + sendtopic_back + '" class="button_submit"/><input type="submit" name="cancel" value="' + sendtopic_close + '" class="button_submit"/>'; |
|
1300
|
|
|
|
|
1301
|
|
|
oPopup_body.html(text); |
|
1302
|
|
|
oPopup_body.find('input[name="send"]').each(function () { |
|
1303
|
|
|
$(this).on('click', function (event) { |
|
1304
|
|
|
event.preventDefault(); |
|
1305
|
|
|
data = $(oPopup_body).find('form').serialize() + '&send=1'; |
|
1306
|
|
|
sendtopicForm(oPopup_body, url, oContainer); |
|
1307
|
|
|
}); |
|
1308
|
|
|
}); |
|
1309
|
|
|
|
|
1310
|
|
|
// Cancel means cancel |
|
1311
|
|
|
oPopup_body.find('input[name="cancel"]').each(function () { |
|
1312
|
|
|
$(this).on('click', function (event) { |
|
1313
|
|
|
event.preventDefault(); |
|
1314
|
|
|
oContainer.hide(); |
|
1315
|
|
|
}); |
|
1316
|
|
|
}); |
|
1317
|
|
|
} |
|
1318
|
|
|
|
|
1319
|
|
|
if (oElement.getElementsByTagName('url').length !== 0) |
|
1320
|
|
|
{ |
|
1321
|
|
|
var url_redir = oElement.getElementsByTagName('url')[0].firstChild.nodeValue; |
|
1322
|
|
|
oPopup_body.html(sendtopic_error.replace('{href}', url_redir)); |
|
1323
|
|
|
} |
|
1324
|
|
|
} |
|
1325
|
|
|
}) |
|
1326
|
|
|
.fail(function() { |
|
1327
|
|
|
oPopup_body.html(sendtopic_error.replace('{href}', url)); |
|
1328
|
|
|
}); |
|
1329
|
|
|
}); |
|
1330
|
|
|
} |
|
1331
|
|
|
|
|
1332
|
|
|
|
|
1333
|
|
|
|
|
1334
|
|
|
/** |
|
1335
|
|
|
* Used to split a topic. |
|
1336
|
|
|
* Allows selecting a message so it can be moved from the original to the spit topic or back |
|
1337
|
|
|
* |
|
1338
|
|
|
* @param {string} direction up / down / reset |
|
1339
|
|
|
* @param {int} msg_id message id that is being moved |
|
1340
|
|
|
*/ |
|
1341
|
|
|
function topicSplitselect(direction, msg_id) |
|
1342
|
|
|
{ |
|
1343
|
|
|
getXMLDocument(elk_prepareScriptUrl(elk_scripturl) + "action=splittopics;sa=selectTopics;subname=" + topic_subject + ";topic=" + topic_id + "." + start[0] + ";start2=" + start[1] + ";move=" + direction + ";msg=" + msg_id + ";xml", onTopicSplitReceived); |
|
1344
|
|
|
return false; |
|
1345
|
|
|
} |
|
1346
|
|
|
|
|
1347
|
|
|
/** |
|
1348
|
|
|
* Callback function for topicSplitselect |
|
1349
|
|
|
* |
|
1350
|
|
|
* @param {xmlCallback} XMLDoc |
|
1351
|
|
|
*/ |
|
1352
|
|
|
function onTopicSplitReceived(XMLDoc) |
|
1353
|
|
|
{ |
|
1354
|
|
|
var i, |
|
1355
|
|
|
j, |
|
1356
|
|
|
pageIndex; |
|
1357
|
|
|
|
|
1358
|
|
|
// Find the selected and not_selected page index containers |
|
1359
|
|
|
for (i = 0; i < 2; i++) |
|
1360
|
|
|
{ |
|
1361
|
|
|
pageIndex = XMLDoc.getElementsByTagName("pageIndex")[i]; |
|
1362
|
|
|
|
|
1363
|
|
|
// Update the page container with our xml response |
|
1364
|
|
|
document.getElementById("pageindex_" + pageIndex.getAttribute("section")).innerHTML = pageIndex.firstChild.nodeValue; |
|
1365
|
|
|
start[i] = pageIndex.getAttribute("startFrom"); |
|
1366
|
|
|
} |
|
1367
|
|
|
|
|
1368
|
|
|
var numChanges = XMLDoc.getElementsByTagName("change").length, |
|
1369
|
|
|
curChange, |
|
1370
|
|
|
curSection, |
|
1371
|
|
|
curAction, |
|
1372
|
|
|
curId, |
|
1373
|
|
|
curList, |
|
1374
|
|
|
newItem, |
|
1375
|
|
|
sInsertBeforeId, |
|
1376
|
|
|
oListItems, |
|
1377
|
|
|
right_arrow = '<i class="icon icon-lg i-chevron-circle-right"></i>', |
|
1378
|
|
|
left_arrow = '<i class="icon icon-lg i-chevron-circle-left"></i>'; |
|
1379
|
|
|
|
|
1380
|
|
|
// Loop through all of the changes returned in the xml response |
|
1381
|
|
|
for (i = 0; i < numChanges; i++) |
|
1382
|
|
|
{ |
|
1383
|
|
|
curChange = XMLDoc.getElementsByTagName("change")[i]; |
|
1384
|
|
|
curSection = curChange.getAttribute("section"); |
|
1385
|
|
|
curAction = curChange.getAttribute("curAction"); |
|
1386
|
|
|
curId = curChange.getAttribute("id"); |
|
1387
|
|
|
curList = document.getElementById("messages_" + curSection); |
|
1388
|
|
|
|
|
1389
|
|
|
// Remove it from the source list so we can insert it in the destination list |
|
1390
|
|
|
if (curAction === "remove") |
|
1391
|
|
|
curList.removeChild(document.getElementById(curSection + "_" + curId)); |
|
1392
|
|
|
// Insert a message. |
|
1393
|
|
|
else |
|
1394
|
|
|
{ |
|
1395
|
|
|
// By default, insert the element at the end of the list. |
|
1396
|
|
|
sInsertBeforeId = null; |
|
1397
|
|
|
|
|
1398
|
|
|
// Loop through the list to try and find an item to insert after. |
|
1399
|
|
|
oListItems = curList.getElementsByTagName("li"); |
|
1400
|
|
|
for (j = 0; j < oListItems.length; j++) |
|
1401
|
|
|
{ |
|
1402
|
|
|
if (parseInt(oListItems[j].id.substr(curSection.length + 1)) < curId) |
|
1403
|
|
|
{ |
|
1404
|
|
|
// This would be a nice place to insert the row. |
|
1405
|
|
|
sInsertBeforeId = oListItems[j].id; |
|
1406
|
|
|
|
|
1407
|
|
|
// We're done for now. Escape the loop. |
|
1408
|
|
|
j = oListItems.length + 1; |
|
1409
|
|
|
} |
|
1410
|
|
|
} |
|
1411
|
|
|
|
|
1412
|
|
|
// Let's create a nice container for the message. |
|
1413
|
|
|
newItem = document.createElement("li"); |
|
1414
|
|
|
newItem.className = ""; |
|
1415
|
|
|
newItem.id = curSection + "_" + curId; |
|
1416
|
|
|
newItem.innerHTML = '' + |
|
1417
|
|
|
'<div class="content">' + |
|
1418
|
|
|
'<div class="message_header">' + |
|
1419
|
|
|
'<a class="split_icon float' + (curSection === "selected" ? "left" : "right") + '" href="' + elk_prepareScriptUrl(elk_scripturl) + 'action=splittopics;sa=selectTopics;subname=' + topic_subject + ';topic=' + topic_id + '.' + not_selected_start + ';start2=' + selected_start + ';move=' + (curSection === "selected" ? "up" : "down") + ';msg=' + curId + '" onclick="return topicSplitselect(\'' + (curSection === "selected" ? 'up' : 'down') + '\', ' + curId + ');">' + |
|
1420
|
|
|
(curSection === "selected" ? left_arrow : right_arrow) + |
|
1421
|
|
|
'</a>' + |
|
1422
|
|
|
'<strong>' + curChange.getElementsByTagName("subject")[0].firstChild.nodeValue + '</strong> ' + txt_by + ' <strong>' + curChange.getElementsByTagName("poster")[0].firstChild.nodeValue + '</strong>' + |
|
1423
|
|
|
'<br />' + |
|
1424
|
|
|
'<em>' + curChange.getElementsByTagName("time")[0].firstChild.nodeValue + '</em>' + |
|
1425
|
|
|
'</div>' + |
|
1426
|
|
|
'<div class="post">' + curChange.getElementsByTagName("body")[0].firstChild.nodeValue + '</div>' + |
|
1427
|
|
|
'</div>'; |
|
1428
|
|
|
|
|
1429
|
|
|
// So, where do we insert it? |
|
1430
|
|
|
if (typeof sInsertBeforeId === "string") |
|
1431
|
|
|
curList.insertBefore(newItem, document.getElementById(sInsertBeforeId)); |
|
1432
|
|
|
else |
|
1433
|
|
|
curList.appendChild(newItem); |
|
1434
|
|
|
} |
|
1435
|
|
|
} |
|
1436
|
|
|
} |
|
1437
|
|
|
|